
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>政策维护</title>
    <script src="../../../res/js/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="../../../res/layui/css/pulas.css" media="all">
</head>
<body>

<style>
    .laytable-cell-1-0-3 {
        width: 170px;
        font-family: fantasy;
        color: salmon;
    }
    .laytable-cell-1-0-6 {
        width: 170px;
        font-family: fantasy;
        color: blue;
    }
</style>
<div class="demoTable">

    <input type="hidden" name="recordId" id="recordId" >

    <input type="hidden" id="informId" name="informId">

    <div class="layui-inline">
        <input class="labtna" name="materialName" id="materialName" autocomplete="off" placeholder="输入政策名称">
    </div>


    <div class="layui-inline layui-form">
        <select name="typeId" id="typeId"  class="labtna"  >
            <option value="">
                选择公司名称
            </option>
        </select>
    </div>

</div>

<table class="layui-hide" id="materials" lay-filter="demo"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="sal">详情</a>
</script>

<script type="text/javascript" src="../../../res/js/base.js"></script>
<script src="../../../res/layui/layui.js"></script>
<script>

    layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
             layer = layui.layer //弹层
            ,table = layui.table //表格
            ,upload = layui.upload //上传
            ,form=layui.form
            ,element = layui.element; //元素操作
        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.msg('切换了：'+ this.innerHTML);
            console.log(data);
        });

        //执行一个 table 实例
        table.render({
            elem: '#materials'
            ,height: 490
            ,url: '/record/selectAll' //数据接口            ,page: true //开启分页
            ,method:'post'
            ,cols: [[ //表
                 {field: 'oper', title: '操作人', width:170}
                 ,{field: 'informName', title: '政策名称', width:170}
                ,{field: 'immName', title: '公司名称', width:170}
                ,{field: 'informTime', title: '发布时间', width:170}
                ,{fixed: 'right',title: '操作', width: 252, align:'center', toolbar: '#barDemo'}
            ]]
            ,id: 'testReload'
        });

        //监听工具条
        table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'del'){
                var matId=data.recordId;
                layer.confirm('是否删除此记录？', function(index){
                    layer.close(index);
                    var url = "/record/delect";
                    var data={id:matId};
                    $.post(url,data,function(mes){
                        layer.msg(mes.message);
                        table.reload("testReload");
                    },"json");
                });
            }else if(layEvent === 'sal'){
                layui.use('layer',function(){
                    var layer = layui.layer;   //弹层
                    layer.open({
                        type: 2,
                        title: '政策维护信息',
                        area : ['100%' , '100%'],//弹出框大小
                        shift:1, //弹出框动画效果
                        content: 'moblie.html?informId='+data.informId
                    });
                });
            }
        });


        form.on('select(brickType)', function(data) {
            var val= data.elem[data.elem.selectedIndex].text;
            if(val=="选择公司名称"){
                val="";
            }
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    immName: val
                }
            });
        });

        $(function () {
            $('#materialName').bind('input propertychange', function() {
                var materialName = $('#materialName');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        materialName: materialName.val()
                    }
                });
            });

            url = "/inform/queryAll";
            data = null;
            $.get(url,data,function (obj) {
                $.each(obj,function(index,item){
                    $("#typeId").append("<option value="+item.immId+"> "+item.immName+"</option>");
                })
                //重新渲染
                form.render('select');
            },"json");
        })
    });

</script>
</body>
</html>
